package com.situ.bas.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.bas.entity.BasDict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.bas.service.StorageService;
import com.situ.bas.entity.Storage;
import com.situ.util.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Storage的路由接口服务
 * 
 * @author 
 *
 */
@RestController
public class StorageController {

	/** StorageService服务 */
	@Autowired
	private StorageService storageService;
	
	/**
	 * 查询所有Storage数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "queryStorage", produces = {"application/json;charset=UTF-8"})
	public ResponseData find(Storage value) {

		return ResponseData.ok().putDataValue("list",storageService.find(value));
	}
	
	/**
	 * 通过id查询Storage数据的方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "queryStorageById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData findOne(@PathVariable(name="id") Integer id) {
		 return ResponseData.ok().putDataValue("obj",storageService.findOne(id));
	}
	
	/**
	 * 插入Storage属性不为空的数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "saveStorage")
	public ResponseData save(Storage value) {
		return ResponseData.ok().putDataValue("obj", storageService.saveNotNull(value));
	}
	
	/**
	 * 更新Storage属性不为空的数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "updateStorage", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(Storage value) {
		return ResponseData.ok().putDataValue("obj",storageService.updateNotNullById(value));
	}

	/**
	 * 通过id删除Storage数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delStorageById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delete(@PathVariable(name="id") Integer id) {
		return ResponseData.ok().putDataValue("obj",storageService.deleteById(id));
	}

	@RequestMapping("selectStorageBylike")
	public ResponseData selectStorageBylike(String stk_warehouse,String prod_name,
											@RequestParam(defaultValue ="1", required = false) int startPage ,
											@RequestParam(defaultValue = "5",required = false) int PageSize){
Map<String,String> map=new HashMap();
		map.put("prod_name", prod_name);
		map.put("stk_warehouse", stk_warehouse);
		PageHelper.startPage(startPage,PageSize );
		List<Map> list = storageService.selectStorageBylike(map);
		PageInfo pageInfo=new PageInfo(list,5);
		return ResponseData.ok().putDataValue("pageInfo",pageInfo);
	}
}
